package com.biz.primus.management.order.controller;

import com.biz.primus.model.oms.enums.OrderDeliveryType;
import com.biz.primus.model.oms.enums.OrderPaymentState;
import com.biz.primus.model.oms.vo.OmsOrderVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @note: 人工派单控制层
 * @author: zzy
 * @careat: 2017-11-20 14:25
 **/
@Controller
@RequestMapping("manualSingle")
public class ManualSingleController {

    /**
     * 人工派单列表(首页,跳转)
     * @return
     */
    @GetMapping
    public ModelAndView manualSingle() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manualSingle/list");
        return modelAndView;
    }

    /**
     * 订单跳转详情
     * @return
     */
    @GetMapping("manualSingleDetails")
    public ModelAndView manualSingleDetails () {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manualSingle/details");
        return modelAndView;
    }

    /**
     * 详情跳转改派
     * @return
     */
    @GetMapping("manualSingleReassignment")
    public ModelAndView manualSingleReassignment () {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manualSingle/reassignment");
        return modelAndView;
    }

    @GetMapping("manualSingleList")
    @ResponseBody
    public Map<String, Object> manualSingleList (OrderDeliveryType orderDeliveryType, String code, int start, int length) {
        Map<String, Object> result = new HashMap<>();
        List<OmsOrderVo> list = getAll();
        result.put("iTotalRecords", list.size());//数据总条数
        result.put("iTotalDisplayRecords", list.size());//显示的条数
        result.put("aaData", list);
        return result;
    }


    private List<OmsOrderVo> getAll() {
        List<OmsOrderVo>  result = new LinkedList<>();
        for (int j = 0; j < 6; j++) {
            OmsOrderVo orderItemVO = new OmsOrderVo();
            orderItemVO.setCode("订单编码" + j);
            orderItemVO.setOrderSource("订单来源" + j);
            orderItemVO.setSelfRemark("商家备注" + j);
            orderItemVO.setDeliveryType(OrderDeliveryType.self_now);
            orderItemVO.setPaymentState(OrderPaymentState.cod);
            orderItemVO.setAmount(j);
            orderItemVO.setDeliveryType(OrderDeliveryType.self_now);
            result.add(orderItemVO);
        }
        return result;
    }
}
